package cn.iocoder.yudao.module.infra.dal.dataobject.base;

import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.Base2DO;
import cn.iocoder.yudao.module.infra.api.base.dto.FormNameValueModel;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
@TableName(value = "infra_base_dynamic_table")
public class DynamicTable extends Base2DO implements Serializable {

    @TableId(type = IdType.AUTO)
    private Long id;

    private String dataName;

    private String dataSqlName;

    private String colsJson;

    private boolean canInsert;

    private boolean canUpdate;

    private boolean canDelete;

    private String colClickValue;

    @TableField(exist = false)
    private List<FormNameValueModel> colClickList;

    public void setColClickValue(String colClickValue) {
        this.colClickValue = colClickValue;
        if (StringUtils.isNotBlank(colClickValue)) {
            colClickList = JsonUtils.parseArray(colClickValue, FormNameValueModel.class);
        }
    }
}
